package cn.com.my.yzt;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class ListMap {

	public static void main(String[] args) {
		Map<String, Object> tempMap = new HashMap<String, Object>();
		tempMap.put("a", 1);
		tempMap.put("b", 2);
		tempMap.put("c", 3);
		tempMap.put("phone", "15876519312");
		
	//	jdk1_4(tempMap);
	//	jdk1_5(tempMap);
		
		System.out.println(tempMap.get("a"));
		System.out.println(tempMap.get("phone"));
	}

	public static void jdk1_4(Map<String, Object> tempMap){
		// 遍历方法一 hashmap entrySet() 遍历
		System.out.println("方法一");
		Iterator it = tempMap.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry entry = (Map.Entry) it.next();
			Object key = entry.getKey();
			Object value = entry.getValue();
			System.out.println("key=" + key + " value=" + value);
		}
	}
	
	
	public static void jdk1_5(Map<String, Object> tempMap){
		 // JDK1.5中,应用新特性For-Each循环
		  // 遍历方法二
		  System.out.println("方法二");
		  for (Map.Entry<String, Object> entry : tempMap.entrySet()) {
			  String key = entry.getKey().toString();
			  String value = entry.getValue().toString();
			  System.out.println("key=" + key + " value=" + value);
		  }
	}
	
	
	
}
